package com.od.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.od.service.MessageService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@Controller
@CrossOrigin
@RequestMapping("message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @PostMapping("allMessages")
    @ResponseBody
    public List<Map<String, Object>> allMessage(@RequestBody Map<String, Object> contactData) {
        System.out.println(contactData);
        String messageContact = contactData.get("messageContact").toString();
        return messageService.getMessagesByContact(messageContact);
    }

    @PostMapping("sendMessage")
    @ResponseBody
    public void sendMessage(@RequestBody Map<String, Object> newMessage) {
        System.out.println(newMessage);
        messageService.sendMessage(newMessage);
    }
    

}
